/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.acmwustl.bubble.controllers;

import org.acmwustl.bubble.gui.ConfirmCostFrame;
import org.acmwustl.bubble.gui.PostPurchaseFrame;
import org.acmwustl.bubble.gui.PurchaseDialog;
import org.acmwustl.bubble.logic.ConnectionManager;

/**
 *
 * @author officer
 */
public class PurchaseController {

    PurchaseDialog myParent;

    public PurchaseController(PurchaseDialog pd) {
        myParent = pd;
    }

    public void checkout(int total) {
        ConfirmCostFrame ccf = new ConfirmCostFrame(total, this);
        ccf.setVisible(true);
        myParent.setVisible(false);
    }

    public void cancelPurchase(ConfirmCostFrame ccf) {
        ccf.dispose();
        myParent.setVisible(true);
    }

    public void confirmPurchase(ConfirmCostFrame ccf, String keyID, int amount) {
        //TODO: add support for purchasing.
        //TODO: add the new balance
        ConnectionManager cm = ConnectionManager.getInstance();
        cm.updateBalanceInCents(keyID,cm.getBalanceInCents(keyID) - amount);
        PostPurchaseFrame ppf = new PostPurchaseFrame(cm.getBalanceInCents(keyID));
        ppf.setVisible(true);
        ccf.dispose();
    }
}
